import Singleton from "../../../../scripts/Singleton";
import { LoginRequest } from "./proto";
import { DemoServer } from "./server";

export class Http {
    login( req: LoginRequest){

    }
}

export class WebSocket extends Singleton<WebSocket>{
    
    private _listenEvents:Map<string, Function> = null 
    registerEvent(cmd:string , listen: Function){
        if (this._listenEvents == null) {
            this._listenEvents = new Map()
        }
        this._listenEvents.set(cmd, listen)
    }
    
    send(cmd: string, data?) {
        DemoServer.getInstance().doData(cmd, data)
    }

    doMessage(cmd:string, data){
        if (this._listenEvents.get(cmd)) {
            this._listenEvents.get(cmd)(data) 
        }
    }
}

export let netMgr:WebSocket = WebSocket.getInstance()
